package cn.tedu.bece.front.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.tedu.bece.front.common.exception.ServiceException;
import cn.tedu.bece.front.mapper.BabyMapper;
import cn.tedu.bece.front.mapper.GrowthRecordMapper;
import cn.tedu.bece.front.pojo.dto.BabyQuery;
import cn.tedu.bece.front.pojo.dto.BabySaveParam;
import cn.tedu.bece.front.pojo.dto.GrowthRecordQuery;
import cn.tedu.bece.front.pojo.dto.GrowthRecordSaveParam;
import cn.tedu.bece.front.pojo.entity.Baby;
import cn.tedu.bece.front.pojo.entity.GrowthRecord;
import cn.tedu.bece.front.pojo.vo.BabyVO;
import cn.tedu.bece.front.pojo.vo.GrowthRecordVO;
import cn.tedu.bece.front.service.GrowthRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class GrowthRecordServiceImpl implements GrowthRecordService {

    @Autowired
    GrowthRecordMapper growthRecordMapper;
    @Autowired
    BabyMapper babyMapper;

    @Override
    public void add(GrowthRecordSaveParam growthRecordSaveParam) {
        log.debug("添加宝宝成长记录业务：参数：{}",growthRecordSaveParam);
        GrowthRecord growthRecord = new GrowthRecord();
        BeanUtils.copyProperties(growthRecordSaveParam, growthRecord);
        Integer userId = StpUtil.getLoginIdAsInt();
        growthRecord.setUserId(userId);
        growthRecord.setCreateTime(new Date());
        growthRecordMapper.add(growthRecord);
    }

    @Override
    public List<GrowthRecordVO> selectRecord(GrowthRecordQuery growthRecordQuery) {
        log.debug("查询宝宝成长记录业务：参数：{}",growthRecordQuery);
        List<GrowthRecordVO> list = growthRecordMapper.selectRecord(growthRecordQuery);
        return list;
    }
}
